const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
  entry: './src/main.js',
  output: {
    // filename: 'bundle.js',
    path: path.join(__dirname, 'output'),
    // publicPath: 'output/' // 指定网站的根目录，默认为空是指代项目的根目录
  },
  module: {
    rules: [
      {
        test: /.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader', // 取代webpack默认的js加载器，可以进行新特性的转换
          options: {
            presets: [ 
              // 指定新特性转换的插件集合
              // 强制转换为ESM，以防tree shaking失效
              ['@babel/preset-env', { modules: false /*'commonjs'*/ } ] 
            ]
          }
        }
      },
      {
        test: /.vue$/,
        use: ['vue-loader']
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 10 * 1024,
            esModule: false
          }
        }
      },
      {
        test: /\.(vue|js)$/,
        loader: 'eslint-loader',
        exclude: /node_modules/,
        enforce: 'pre'
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin()
  ]
}